package com.gdut.simple.view.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.gdut.simple.R;
import com.gdut.simple.common.DisplayUtil;
import com.gdut.simple.view.adapter.base.AbsRecyclerAdapter;
import com.gdut.simple.view.adapter.base.AbsViewHolder;
import com.squareup.picasso.Picasso;

import java.util.List;

public class ImageGridAdapter extends AbsRecyclerAdapter<String> {

    public ImageGridAdapter(Context context, List<String> list) {
        super(context, list);
    }

    @Override
    protected AbsViewHolder createHolder(ViewGroup parent, int viewType) {
        View view = mInflater.inflate(R.layout.layout_full_image, parent, false);
        return new ImageHolder(view);
    }

    @Override
    protected void showViewHolder(AbsViewHolder holder, int position) {
        ImageHolder imageHolder = (ImageHolder) holder;
        Picasso.with(mContext)
                .load(mData.get(position))
                .error(R.drawable.ic_load_error)
                .placeholder(R.drawable.ic_place_holder)
                .config(Bitmap.Config.RGB_565)
                .into(imageHolder.imageView);

    }

    @Override
    public int getItemCount() {
        return mData != null ? mData.size() : 0;
    }

    private static class ImageHolder extends AbsViewHolder {

        ImageView imageView;

        ImageHolder(View itemView) {
            super(itemView);
            imageView = (ImageView) itemView.findViewById(R.id.id_image_view);
        }
    }
}
